//import org.activiti.bpmn.model.*;
//import org.activiti.engine.*;
//import org.activiti.engine.history.HistoricProcessInstance;
//import org.activiti.engine.history.HistoricTaskInstance;
//import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
//import org.activiti.engine.repository.Deployment;
//import org.activiti.engine.repository.ProcessDefinition;
//import org.activiti.engine.runtime.Execution;
//import org.activiti.engine.runtime.ProcessInstance;
//import org.activiti.engine.task.IdentityLink;
//import org.activiti.engine.task.Task;
//import org.activiti.image.ProcessDiagramGenerator;
//import org.activiti.image.impl.DefaultProcessDiagramGenerator;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.context.support.ClassPathXmlApplicationContext;
//import org.springframework.stereotype.Component;
//
//import java.io.File;
//import java.io.InputStream;
//import java.util.*;
//
////import org.activiti5.engine.impl.pvm.PvmActivity;
////import org.activiti5.engine.impl.pvm.PvmTransition;
////import org.activiti5.engine.impl.pvm.process.ActivityImpl;
//
//
//@Component
//@ConditionalOnClass(ProcessEngine.class)
//public class MyActivitiUtilFor6x {
//
//    public ClassPathXmlApplicationContext context;
//    @Autowired
//    public ProcessEngine processEngine;
//    @Autowired
//    public RuntimeService runtimeService;
//    @Autowired
//    public RepositoryService repositoryService;
//    @Autowired
//    public TaskService taskService;
//    @Autowired
//    public ManagementService managementService;
//    @Autowired
//    public IdentityService identityService;
//    @Autowired
//    public HistoryService historyService;
//    @Autowired
//    public FormService formService;
//    public Logger log = LoggerFactory.getLogger(this.getClass());
//
//    /**
//     * 构造函数
//     */
//    public MyActivitiUtilFor6x() {
//
//    }
//
//    /**
//     * 构造函数
//     *
//     * @param SpringCfgXmlPathForActiviti activiti-spring配置文件位置
//     *                                    使用classpath的路径例如com/thd/activiti/activiti.cfg1.xml
//     */
//    public MyActivitiUtilFor6x(String SpringCfgXmlPathForActiviti) {
//        System.out.println("---- MyActivitiUtil Construction ："
//                + SpringCfgXmlPathForActiviti);
//        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
//                new String[]{SpringCfgXmlPathForActiviti});
//        processEngine = (ProcessEngine) context.getBean("processEngine");
//        runtimeService = (RuntimeService) context.getBean("runtimeService");
//        repositoryService = (RepositoryService) context
//                .getBean("repositoryService");
//        taskService = (TaskService) context.getBean("taskService");
//        managementService = (ManagementService) context
//                .getBean("managementService");
//
//        identityService = (IdentityService) context.getBean("identityService");
//        historyService = (HistoryService) context.getBean("historyService");
//        formService = (FormService) context.getBean("formService");
//    }
//
//    /**
//     * 部署流程 Method Description : 部署流程
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param bpmnPath bpmn的所在包路径
//     * @return
//     */
//    public Deployment deploy(String bpmnPath) {
//        System.out.println("================ deploy [" + bpmnPath + "] Start ===================");
//        Deployment deploy = repositoryService.createDeployment().addClasspathResource(bpmnPath).deploy();
//        System.out.println("---- 部署ID：" + deploy.getId());
//        System.out.println("================ deploy [" + bpmnPath + "] End ===================");
//        return deploy;
//    }
//
//
//    /**
//     * Method Description : 删除已部署的流程
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param deploymentId 部署ID
//     * @return
//     */
//    public void deleteDeploy(String deploymentId) {
//        System.out.println("================ deleteDeploy [" + deploymentId + "] Start ===================");
//        //删除流程实例
//        List<ProcessInstance> proInsList = runtimeService.createProcessInstanceQuery().deploymentId(deploymentId).list();
//        if (proInsList != null && proInsList.size() >= 0) {
//            for (ProcessInstance pi : proInsList) {
//                this.runtimeService.deleteProcessInstance(pi.getProcessInstanceId(), "process deploy be deleted");
//            }
//        }
//        //删除流程实例历史
//
//        List<HistoricProcessInstance> hisList = this.historyService.createHistoricProcessInstanceQuery().deploymentId(deploymentId).list();
//        if (hisList != null && hisList.size() >= 0) {
//            for (HistoricProcessInstance hi : hisList) {
//                this.historyService.deleteHistoricProcessInstance(hi.getId());
//            }
//        }
//
//        //删除流程部署
//        repositoryService.deleteDeployment(deploymentId);
//        System.out.println("================ deleteDeploy [" + deploymentId + "] End ===================");
//    }
//
//    /**
//     * 给流程实例添加流程变量
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param map
//     * @param executionId
//     */
//    public void addVarableToExecution(Map map, String executionId) {
//        System.out.println("================ addVarableToExecution  Start ===================");
//        runtimeService.setVariablesLocal(executionId, map);
//        System.out.println("================ addVarableToExecution  End ===================");
//    }
//
//    /**
//     * 给流程实例添加流程变量
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param map
//     * @param processInstanceId
//     */
//    public void addVarableToProcessInstance(Map map, String processInstanceId) {
//        System.out.println("================ addVarableToExecution  Start ===================");
//        runtimeService.setVariables(processInstanceId, map);
//        System.out.println("================ addVarableToExecution  End ===================");
//    }
//
//    /**
//     * 根据流程实例id查询流程变量
//     *
//     * @param processInstanceId
//     * @return
//     */
//    public Map queryVarableByProcessInstanceId(String processInstanceId) {
//        System.out.println("================ queryVarableByProcessInstanceId  Start ===================");
//        System.out.println("================ queryVarableByProcessInstanceId  End ===================");
//        return this.runtimeService.getVariables(processInstanceId);
////		return this.runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessVariables();
//    }
//
//    /**
//     * 根据taskId查询流程变量
//     *
//     * @param taskId
//     * @return
//     */
//    public Map queryVarableByTaskId(String taskId) {
//        System.out.println("================ queryVarableByTaskId  Start ===================");
//        System.out.println("================ queryVarableByTaskId  End ===================");
//        return this.taskService.getVariables(taskId);
//    }
//
//
//    /**
//     * 查询某任务的候选人
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param taskId 任务ID
//     * @return
//     */
//    public List<IdentityLink> queryCandidateForTask(String taskId) {
//        System.out.println("================ queryCandidateForTask [" + taskId + "] Start ===================");
//        List<IdentityLink> candidaters = taskService.getIdentityLinksForTask(taskId);
//        System.out.println("================ queryCandidateForTask [" + taskId + "] End ===================");
//        return candidaters;
//    }
//
//    /**
//     * 查询某人个人待办 Method Description : 查询某人个人待办
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param assignee 人员标识
//     * @return
//     */
//    public List<Task> queryTaskForAssignee(String assignee) {
//        System.out.println("================ queryTaskForAssignee [" + assignee
//                + "] Start ===================");
//        List<Task> tasks = taskService.createTaskQuery().taskAssignee(assignee)
//                .list();
//        if (tasks != null && tasks.size() > 0) {
//            for (Task task : tasks) {
//                System.out.println("===================================");
//                System.out.println("---- instanceId:" + task.getProcessInstanceId());
//                System.out.println("----  executionId:" + task.getExecutionId());
//                System.out.println("----  taskId:" + task.getId());
//                System.out.println("----  taskName: " + task.getName());
//                System.out.println("----  category:" + task.getCategory());
//                System.out.println("===================================");
//            }
//        }
//        System.out.println("================ queryTaskForAssignee [" + assignee
//                + "] End ===================");
//        return tasks;
//    }
//
//
//    /**
//     * 查询某个流程实例的代办
//     *
//     * @param processInstanceId 流程实例ID
//     * @return
//     */
//    public List<Task> queryTaskByProcessInstanceId(String processInstanceId) {
//        List<Task> tasks = this.getTaskService().createTaskQuery().processInstanceId(processInstanceId).list();
//        if (tasks != null && tasks.size() > 0) {
//            for (Task task : tasks) {
//                System.out.println("===================================");
//                System.out.println("---- instanceId:" + task.getProcessInstanceId());
//                System.out.println("----  executionId:" + task.getExecutionId());
//                System.out.println("----  taskId:" + task.getId());
//                System.out.println("----  taskName: " + task.getName());
//                System.out.println("----  category:" + task.getCategory());
//                System.out.println("===================================");
//            }
//        }
//        return tasks;
//
//    }
//
//    /**
//     * 查询某个流程实例的代办
//     *
//     * @param businessKey 业务主键
//     * @return
//     */
//    public List<Task> queryTaskByBusinessNo(String businessKey) {
//        if (StringUtils.isEmpty(businessKey)) {
//            return new ArrayList<Task>();
//        }
//        List<Task> tasks = this.getTaskService().createTaskQuery().processInstanceBusinessKey(businessKey).list();
//        if (tasks != null && tasks.size() > 0) {
//            for (Task task : tasks) {
////				System.out.println("===================================");
////				System.out.println("---- instanceId:" + task.getProcessInstanceId());
////				System.out.println("----  executionId:" + task.getExecutionId());
////				System.out.println("----  taskId:" + task.getId());
////				System.out.println("----  taskName: " + task.getName());
////				System.out.println("----  category:" + task.getCategory());
////				System.out.println("===================================");
//            }
//        }
//
//
//        return tasks;
//
//    }
//
//
//    /**
//     * 查询某个代办信息
//     *
//     * @param taskId 代办ID
//     * @return
//     */
//    public Map queryTaskByTaskId(String taskId) {
//        Task task = this.getTaskService().createTaskQuery().taskId(taskId).singleResult();
////		System.out.println("===================================");
////		System.out.println("---- instanceId:" + task.getProcessInstanceId());
////		System.out.println("----  executionId:" + task.getExecutionId());
////		System.out.println("----  taskId:" + task.getId());
////		System.out.println("----  taskName: " + task.getName());
////		System.out.println("----  category:" + task.getCategory());
////		System.out.println("----  Assignee:" + task.getAssignee());
////		System.out.println("----  Owner:" + task.getOwner());
//        List identityLinkList = this.taskService.getIdentityLinksForTask(taskId);
//
//        List candidates = new ArrayList();
//        if (identityLinkList != null && identityLinkList.size() > 0) {
//            for (Iterator iterator = identityLinkList.iterator(); iterator.hasNext(); ) {
//                IdentityLink identityLink = (IdentityLink) iterator.next();
//                if (identityLink.getUserId() != null) {
//                    System.out.println("----  candidate:" + identityLink.getUserId());
//                    candidates.add(identityLink.getUserId());
//                }
//            }
//        }
//
//        ProcessInstance pi = this.getRuntimeService().createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
//
//
//        Map m = new HashMap();
//        m.put("taskDefinitionKey", task.getTaskDefinitionKey());
//        m.put("processDefinedName", pi.getProcessDefinitionName());
//        m.put("instanceId", task.getProcessInstanceId());
//        m.put("executionId", task.getExecutionId());
//        m.put("taskId", task.getId());
//        m.put("taskName", task.getName());
//        m.put("category", task.getCategory());
//        m.put("Assignee", task.getAssignee());
//        m.put("Owner", task.getOwner());
//        m.put("candidates", candidates);
//        m.put("bussinessKey", pi.getBusinessKey());
//        System.out.println("===================================");
//        return m;
//
//    }
//
//    /**
//     * 查询某人的组待办 Method Description : 查询某人的组待办
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param candidate 人员标识
//     * @return
//     */
//    public List<Task> queryTaskForCandidate(String candidate) {
//        System.out.println("================ queryTaskForCandidate [" + candidate
//                + "] Start ===================");
//        List<Task> tasks = taskService.createTaskQuery()
//                .taskCandidateUser(candidate).list();
//        if (tasks != null && tasks.size() > 0) {
//            for (Task task : tasks) {
//                System.out.println("===================================");
//                System.out.println("---- instanceId:" + task.getProcessInstanceId());
//                System.out.println("----  executionId:" + task.getExecutionId());
//                System.out.println("----  taskId:" + task.getId());
//                System.out.println("----  taskName: " + task.getName());
//                System.out.println("----  category:" + task.getCategory());
//                System.out.println("===================================");
//            }
//        }
//        System.out.println("================ queryTaskForCandidate [" + candidate
//                + "] End ===================");
//        return tasks;
//    }
//
//    /**
//     * 查询某人个人待办和组待办 Method Description : 查询某人个人待办和组待办
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param assigneeOrcandidate 人员标识
//     * @return
//     */
//    public List<Task> queryTaskForUser(String assigneeOrcandidate) {
//        System.out.println("================ queryTaskForUser [" + assigneeOrcandidate
//                + "] Start ===================");
//        List<Task> taskList = new ArrayList<Task>();
//        taskList.addAll(queryTaskForAssignee(assigneeOrcandidate));
//        taskList.addAll(queryTaskForCandidate(assigneeOrcandidate));
//        System.out.println("================ queryTaskForUser [" + assigneeOrcandidate
//                + "] End ===================");
//        return taskList;
//    }
//
//    /**
//     * 完成某任务 Method Description : 完成某任务
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param taskId      任务ID
//     * @param variableMap 流程变量
//     */
//    public void completeTask(String taskId, Map<String, Object> variableMap) {
//        System.out.println("================ complateTask  taskId:[" + taskId
//                + "] Start ===================");
//        if (variableMap == null) {
//            taskService.complete(taskId);
//        } else {
//            taskService.complete(taskId, variableMap);
//        }
//        System.out.println("================ complateTask  taskId:[" + taskId
//                + "] End ===================");
//    }
//
//    /**
//     * 签收某任务 Method Description : 签收某任务
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param taskId 任务ID
//     * @param userId 人员ID
//     */
//    public void claimTask(String taskId, String userId) {
//        System.out.println("================ claimTask  taskId:[" + taskId
//                + "]  userId:[" + userId + "]Start ===================");
//        taskService.claim(taskId, userId);
//        System.out.println("================ claimTask  taskId:[" + taskId
//                + "]  userId:[" + userId + "]End ===================");
//    }
//
//    /**
//     * 签收并完成某任务 Method Description : 签收并完成某任务
//     * 5.x OK
//     * 6.x OK
//     *
//     * @param taskId      任务ID
//     * @param userId      人员ID
//     * @param variableMap 流程变量
//     */
//    public void claimAndComplateTask(String taskId, String userId,
//                                     Map<String, Object> variableMap) {
//        System.out.println("================ takeTask  taskId:[" + taskId + "]  userId:["
//                + userId + "]Start ===================");
//        taskService.claim(taskId, userId);
//        if (variableMap == null) {
//            completeTask(taskId, null);
//        } else {
//            completeTask(taskId, variableMap);
//        }
//        System.out.println("================ takeTask  taskId:[" + taskId + "]  userId:["
//                + userId + "]End ===================");
//    }
//
//    /**
//     * 挂起某个流程实例 Method Description : 挂起某个流程实例
//     *
//     * @param processInstanceId 流程实例ID
//     */
//    public void suspendsProcessInstance(String processInstanceId) {
//        System.out.println("================ suspendsProcessInstance  processInstanceId:["
//                + processInstanceId + "] Start ===================");
//        runtimeService.suspendProcessInstanceById(processInstanceId);
//        System.out.println("================ suspendsProcessInstance  processInstanceId:["
//                + processInstanceId + "] End ===================");
//    }
//
//    /**
//     * 激活某个已挂起的流程实例 Method Description : 激活某个已挂起的流程实例
//     *
//     * @param processInstanceId 流程实例ID
//     */
//    public void activateProcessInstance(String processInstanceId) {
//        System.out.println("================ activateProcessInstance  processInstanceId:["
//                + processInstanceId + "] Start ===================");
//        runtimeService.activateProcessInstanceById(processInstanceId);
//
//        System.out.println("================ activateProcessInstance  processInstanceId:["
//                + processInstanceId + "] End ===================");
//    }
//
//    /**
//     * 删除某个流程实例
//     * Method Description : 删除某个流程实例
//     *
//     * @param processInstanceId 流程实例ID
//     * @param deleteReason      取消原因
//     */
//    public void cancelProcessInstance(String processInstanceId, String deleteReason) {
//        System.out.println("================ cancelProcessInstance  processInstanceId:["
//                + processInstanceId + "] Start ===================");
//        runtimeService.deleteProcessInstance(processInstanceId, deleteReason);
//        System.out.println("================ cancelProcessInstance  processInstanceId:["
//                + processInstanceId + "] End ===================");
//    }
//
//    /**
//     * Method Description : 根据流程实例查询当前executions
//     *
//     * @param processInstanceId 流程实例ID
//     * @return List<Execution>
//     */
//    public List<Execution> queryCurrentExecutes(String processInstanceId) {
//        List<Execution> executionList = runtimeService.createExecutionQuery()
//                .processInstanceId(processInstanceId).list();
//        return executionList;
//    }
//
//    /**
//     * Method Description : 根据流程实例查询当前task
//     *
//     * @param processInstanceId 流程实例ID
//     * @return List<Task>
//     */
//    public List<Task> queryCurrentTaskByProcessInstanceId(
//            String processInstanceId) {
//        List<Task> taskList = taskService.createTaskQuery()
//                .processInstanceId(processInstanceId).list();
//        return taskList;
//
//    }
//
//    /**
//     * Method Description : 根据业务主键查询当前task
//     *
//     * @param businessKey 业务主键
//     * @return
//     */
//    public List<Task> queryCurrentTaskByBusinessKey(String businessKey) {
//        List<Task> taskList = taskService.createTaskQuery()
//                .processInstanceBusinessKey(businessKey).list();
//        return taskList;
//    }
//
//    /**
//     * 获取task的下一步节点
//     * 5.x failure
//     * 6.x ok
//     *
//     * @param taskId
//     * @return
//     */
//    public List<FlowElement> queryNextTaskByCurrentTaskId(String taskId) {
//        List<FlowElement> nextNodes = new ArrayList<FlowElement>();
//        Task task = processEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
//        ExecutionEntity ee = (ExecutionEntity) processEngine.getRuntimeService().createExecutionQuery().executionId(task.getExecutionId()).singleResult();
//        //当前节点
//        String crruentActivityId = ee.getActivityId();
//        //获取流程的bpmn
//        BpmnModel bpmnModel = processEngine.getRepositoryService().getBpmnModel(task.getProcessDefinitionId());
//        FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(crruentActivityId);
//        // 输出连线
//        List<SequenceFlow> outFlows = flowNode.getOutgoingFlows();
//        for (SequenceFlow sequenceFlow : outFlows) {
//            // 下一个节点
//            FlowElement targetFlow = sequenceFlow.getTargetFlowElement();
//            nextNodes.add(targetFlow);
//            if (targetFlow instanceof EndEvent) {// 如果下个节点为结束节点
//                System.out.println(sequenceFlow.getId() + "," + sequenceFlow.getName() + "," + sequenceFlow.getTargetFlowElement());
//            }
//        }
//        return nextNodes;
//
//    }
//
//    /**
//     * 获取task的上一步节点
//     * 5.x failure
//     * 6.x ok
//     *
//     * @param taskId
//     * @return
//     */
//    public List<FlowElement> queryPrevTaskByCurrentTaskId(String taskId) {
//        List<FlowElement> nextNodes = new ArrayList<FlowElement>();
//        Task task = processEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
//        ExecutionEntity ee = (ExecutionEntity) processEngine.getRuntimeService().createExecutionQuery().executionId(task.getExecutionId()).singleResult();
//        //当前节点
//        String crruentActivityId = ee.getActivityId();
//        //获取流程的bpmn
//        BpmnModel bpmnModel = processEngine.getRepositoryService().getBpmnModel(task.getProcessDefinitionId());
//        FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(crruentActivityId);
//        // 输入连线
//        List<SequenceFlow> inFlows = flowNode.getIncomingFlows();
//        for (SequenceFlow sequenceFlow : inFlows) {
//            // 上一个节点
//            FlowElement targetFlow = sequenceFlow.getSourceFlowElement();
//            nextNodes.add(targetFlow);
//            if (targetFlow instanceof StartEvent) {// 如果上个节点为开始节点
//                System.out.println(sequenceFlow.getId() + "," + sequenceFlow.getName() + "," + sequenceFlow.getTargetFlowElement());
//            }
//        }
//        return nextNodes;
//
//    }
//
//    /**
//     * 自由流
//     * 5.x failure
//     * 6.x ok
//     * @param taskId 待办ID
//     * @param targetNode 目标节点名称
//     */
////	public void jump(String taskId,String targetNode){
////		processEngine.getManagementService().executeCommand(new JumpAnyWhereCmd(taskId,targetNode));
////	}
//
////
////	public List<PvmActivity> queryPrevTaskByCurrentTaskId(String taskId) {
////		List<PvmActivity> resultList = new ArrayList<PvmActivity>();
////		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
////
////		ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
////				.getDeployedProcessDefinition(task.getProcessDefinitionId());
////		List<ActivityImpl> activitiList = def.getActivities();
////
////		String excId = task.getExecutionId();
////		ExecutionEntity execution = (ExecutionEntity) runtimeService
////				.createExecutionQuery().executionId(excId).singleResult();
////		String activitiId = execution.getActivityId();
////
////		for (ActivityImpl activityImpl : activitiList) {
////			String id = activityImpl.getId();
////			if (activitiId.equals(id)) {
////				//System.out.println("当前任务：" + activityImpl.getProperty("name")); // 输出某个节点的某种属性
////				List<PvmTransition> inTransitions = activityImpl.getIncomingTransitions();// 获取到某个节点出来的所有线路
////				for (PvmTransition tr : inTransitions) {
////					PvmActivity ac = tr.getSource(); // 获取线路的终点节点
////					//System.out.println("上一步任务任务NAME：" + ac.getProperty("name"));
////					//System.out.println("上一步任务任务ID：" + ac.getId());
////					resultList.add(ac);
////				}
////				break;
////			}
////		}
////		return resultList;
////	}
////
////	/**
////	 *
////	 * Method Description : 查询当前待办的下一步待办
////	 * @param taskId 当前待办ID
////	 * @return
////	 */
////	public List<PvmActivity> queryNextTaskByCurrentTaskId(String taskId) {
////		List<PvmActivity> resultList = new ArrayList<PvmActivity>();
////		Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
////		ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
////				.getDeployedProcessDefinition(task.getProcessDefinitionId());
////		List<ActivityImpl> activitiList = def.getActivities();
////		String excId = task.getExecutionId();
////		ExecutionEntity execution = (ExecutionEntity) runtimeService
////				.createExecutionQuery().executionId(excId).singleResult();
////		String activitiId = execution.getActivityId();
////
////		for (ActivityImpl activityImpl : activitiList) {
////			String id = activityImpl.getId();
////			if (activitiId.equals(id)) {
////				//System.out.println("当前任务：" + activityImpl.getProperty("name")); // 输出某个节点的某种属性
////				List<PvmTransition> outTransitions = activityImpl
////						.getOutgoingTransitions();// 获取从某个节点出来的所有线路
////				for (PvmTransition tr : outTransitions) {
////					PvmActivity ac = tr.getDestination(); // 获取线路的终点节点
////					//System.out.println("下一步任务任务NAME：" + ac.getProperty("name"));
////					//System.out.println("下一步任务任务ID：" + ac.getId());
////					resultList.add(ac);
////				}
////				break;
////			}
////		}
////		return resultList;
////	}
////
////	/**
////	 * @param currentTaskEntity
////	 *            当前任务节点
////	 * @param targetTaskDefinitionKey
////	 *            目标任务节点（在模型定义里面的节点名称）
////	 */
////	private void jump(final TaskEntity currentTaskEntity,
////					  String targetTaskDefinitionKey) {
////
////		String processDefinitionId = currentTaskEntity.getProcessDefinitionId();
////		RepositoryServiceImpl repositoryServiceImpl = (RepositoryServiceImpl) repositoryService;
////		ProcessDefinitionEntity pde =  (ProcessDefinitionEntity) repositoryServiceImpl.getDeployedProcessDefinition(processDefinitionId);
////
////		//ProcessDefinitionEntity pde = getProcessDefinition(processEngine,currentTaskEntity.getProcessDefinitionId());
////		final ActivityImpl activity = pde.findActivity(targetTaskDefinitionKey);
////
////		final ExecutionEntity execution = (ExecutionEntity) runtimeService
////				.createExecutionQuery()
////				.executionId(currentTaskEntity.getExecutionId()).singleResult();
////
////		((RuntimeServiceImpl) runtimeService).getCommandExecutor().execute(
////				new Command<Void>() {
////					public Void execute(CommandContext commandContext) {
////
////						// 创建新任务
////						execution.setActivity(activity);
////						execution.executeActivity(activity);
////
////						// 删除当前的任务
////						// 不能删除当前正在执行的任务，所以要先清除掉关联
////						currentTaskEntity.setExecutionId(null);
////						taskService.saveTask(currentTaskEntity);
////						taskService.deleteTask(currentTaskEntity.getId(), true);
////						return null;
////					}
////				});
////
////	}
////	/* ---------------------- 自由流 start ----------------------- */
////	/**
////	 * 跳转至指定活动节点
////	 * @param processInstanceId 流程实例ID
////	 * @param targetTaskDefinitionKey 目标节点ID(XML定义的活动节点的ID属性)
////	 */
////	public void jump(String processInstanceId, String targetTaskDefinitionKey) {
////		TaskEntity currentTask = (TaskEntity) processEngine.getTaskService()
////				.createTaskQuery().processInstanceId(processInstanceId)
////				.singleResult();
////		jump(currentTask, targetTaskDefinitionKey);
////	}
//
//
//    /**
//     * 设置/删除 某个任务的代办人
//     *
//     * @param taskId 任务id
//     * @param userId 代办人id 如果删除则值为空即可
//     */
//    public void assignAssigneeForTask(String taskId, String userId) {
//        taskService.setAssignee(taskId, userId);
//    }
//
//    /**
//     * Method Description : 为某个Task添加候选人
//     *
//     * @param taskId 任务ID
//     * @param userId 人员ID
//     */
//    public void addCandidateUserToTask(String taskId, String userId) {
//        taskService.addCandidateUser(taskId, userId);
//    }
//
//
//    /**
//     * 设置任务的候选人(批量)
//     *
//     * @param taskId  任务id
//     * @param userIds 候选人id集合
//     */
//    public void addCadidatesForTask(String taskId, List<String> userIds) {
//        if (userIds != null && !userIds.isEmpty()) {
//            //Task t = myActivitiUtilFor6x.getTaskService().createTaskQuery().taskId(taskId).singleResult();
//            userIds.forEach(userId -> {
//                this.taskService.addCandidateUser(taskId, userId);
//            });
//        }
//    }
//
//    /**
//     * 某处任务的候选人(批量)
//     *
//     * @param taskId  任务id
//     * @param userIds 候选人id集合
//     */
//    public void deleteCadidatesForTask(String taskId, List<String> userIds) {
//        if (userIds != null && !userIds.isEmpty()) {
//            //Task t = myActivitiUtilFor6x.getTaskService().createTaskQuery().taskId(taskId).singleResult();
//            userIds.forEach(userId -> {
//                this.taskService.deleteCandidateUser(taskId, userId);
//            });
//        }
//    }
//
//    /**
//     * Method Description : 为某个Task删除加候选人
//     *
//     * @param taskId 任务ID
//     * @param userId 人员ID
//     */
//    public void deleteCandidateUserFromTask(String taskId, String userId) {
//        taskService.deleteCandidateUser(taskId, userId);
//    }
//
//    /**
//     * Method Description : 为某个Task替换候选人
//     *
//     * @param taskId    任务ID
//     * @param oldUserId 已有候选人
//     * @param newUserId 新候选人
//     */
//    public void replaceCandidateUserFromTask(String taskId, String oldUserId,
//                                             String newUserId) {
//        taskService.deleteCandidateUser(taskId, oldUserId);
//        taskService.addCandidateUser(taskId, newUserId);
//    }
//
//    /**
//     * 获取流程定义的所有节点
//     * Method Description : ########
//     *
//     * @param procDefId
//     */
//    public void getAllElement(String procDefId) {
//        try {
//            System.out.println(procDefId);
//            BpmnModel model = repositoryService.getBpmnModel(procDefId);
//            if (model != null) {
//                Collection<FlowElement> flowElements = model.getMainProcess()
//                        .getFlowElements();
//                for (FlowElement e : flowElements) {
//                    System.out.println("flowelement id:" + e.getId()
//                            + "  name:" + e.getName() + "   class:"
//                            + e.getClass().toString());
//
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//
//    public Task queryCurrentTaskDef(String taskId) {
//        Task task = this.taskService.createTaskQuery().taskId(taskId).singleResult();
//        //待办ID(数据库表ID)
//        //task.getId();
//        //待办name(xml定义的name属性)
//        //task.getName();
//        //待办的id(xml定义的id属性)
//        //task.getTaskDefinitionKey();
//        return task;
//    }
//
//
//    /**
//     * 根据流程实例id查询某流程是否已关闭
//     *
//     * @param processInstanceId
//     * @return
//     */
//    public boolean isEndedByProcessInstanceId(String processInstanceId) {
//        List<ProcessInstance> pis = this.runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).list();
//        return (pis == null) || pis.isEmpty();
////		Object obj = this.historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getId();
////		ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
////		return pi.isEnded();
//
//    }
//
//
//    /**
//     * 根据业务主键查询流程是否已经关闭
//     *
//     * @param bussinessKey
//     * @return
//     */
//    public boolean isEndedByBussinessKey(String bussinessKey) {
//        List<ProcessInstance> pis = this.runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(bussinessKey).list();
//        //System.out.println("pis===>"+JSON.toJSONString(pis));
//        return (pis == null) || pis.isEmpty();
//    }
//
//    /**
//     * 根据任务id查询业务主键
//     *
//     * @param taskId
//     * @return
//     */
//    public String queryBusinessKeyByTaskId(String taskId) {
//        Task task = this.getTaskService().createTaskQuery().taskId(taskId).singleResult();
//        ProcessInstance pi = this.runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
//        return pi.getBusinessKey();
//    }
//
//
//    /**
//     * Method Description : 绘制流程图
//     *
//     * @param processDefinedId 流程定义ID
//     * @param imgPath          图片路径 PNG类型的图片
//     * @throws Exception
//     */
//    public void drawBpmn(String processDefinedId, String imgPath) throws Exception {
//        ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinedId);
//        System.out.println(processDefinition.getDiagramResourceName());
//        InputStream imageStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName());
//        File f = new File(imgPath);
//        //FileUtils.copyInputStreamToFile(imageStream, f);
//    }
//
//
//    /**
//     * Method Description : 绘制流程图，待办节点红色显示(在流程图中显示当前步骤)
//     *
//     * @param taskId 待办ID
//     * @throws Exception
//     */
//    public InputStream drawBpmnForInputStreamWithCurrentTask(String taskId) throws Exception {
//        InputStream is = this.getClass().getClassLoader().getResourceAsStream("com/thd/activiti/test06/draw.bpmn");    //获取xml文件流
////      System.out.println(is);
////      XMLInputFactory xmlFactory  = XMLInputFactory.newInstance();
////      XMLStreamReader reader = xmlFactory.createXMLStreamReader(is);
////      BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(reader);
////      ProcessDiagramGenerator pdg = new DefaultProcessDiagramGenerator();
////      System.out.println(runtimeService.getActiveActivityIds("60001"));
////      InputStream img = pdg.generateDiagram(bpmnModel, "png",  runtimeService.getActiveActivityIds("60001"), new ArrayList<String>());
////      System.out.println(img);
////      File f1 = new File("D://ab.png");
////      FileUtils.copyInputStreamToFile(img, f1);
//
//        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
//
//        BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
//        ProcessDiagramGenerator pdg = new DefaultProcessDiagramGenerator();
//        Execution execution = runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
//        System.out.println(runtimeService.getActiveActivityIds(execution.getId()));
//
//
//     /* InputStream img = pdg.generateDiagram(
//      		bpmnModel,
//      		"png",
//      		runtimeService.getActiveActivityIds(execution.getId()),
//      		new ArrayList<String>()
//      		);*/
//
//        InputStream img = pdg.generateDiagram(
//                bpmnModel,
//                "png",
//                runtimeService.getActiveActivityIds(execution.getId()),
//                new ArrayList<String>(),
//                processEngine.getProcessEngineConfiguration().getActivityFontName(),
//                processEngine.getProcessEngineConfiguration().getLabelFontName(),
//                null,
//                null,
//                1.0);
//        return img;
//    }
//
//    /**
//     * Method Description : 绘制流程图，待办节点红色显示(在流程图中显示当前步骤)
//     *
//     * @param taskId  待办ID
//     * @param imgPath 图片位置 PNG类型的图片
//     * @throws Exception
//     */
//    public void drawBpmnWithCurrentTask(String taskId, String imgPath) throws Exception {
//        InputStream img = drawBpmnForInputStreamWithCurrentTask(taskId);
//        //System.out.println(img);
//        File f1 = new File(imgPath);
//        //FileUtils.copyInputStreamToFile(img, f1);
//    }
//
//
//    public String createSqlOfHistoryTask(String processInstanceId) {
//        String sql =
//                " select " +
//                        " taskhis.ID_ as taskHisId, " +
//                        " taskhis.NAME_ as taskName, " +
//                        " taskhis.TASK_DEF_KEY_ as taskKey, " +
//                        " taskhis.START_TIME_ as startTime, " +
//                        " taskhis.END_TIME_ as endTime, " +
//                        " taskhis.ASSIGNEE_ as assignee, " +
//                        " pins.BUSINESS_KEY_ as businessKey, " +
//                        " procdef.KEY_ as procDefKey " +
//                        " from " +
//                        " act_hi_taskinst taskhis " +
//                        " left join act_hi_procinst pins on taskhis.PROC_INST_ID_ = pins.PROC_INST_ID_ " +
//                        " left join act_re_procdef procdef on pins.PROC_DEF_ID_ = procdef.ID_ ";
//        return sql;
//    }
//
//
//    public String createSqlOfCurrentTask(String processInstanceId) {
//        String sql =
//                " select " +
//                        " task.ID_ as taskId, " +
//                        " task.NAME_ as taskName, " +
//                        " task.TASK_DEF_KEY_ as taskKey, " +
//                        " pins.BUSINESS_KEY_ as businessKey, " +
//                        " procdef.KEY_ as procDefKey, " +
//                        " t.GROUP_USER as groupUser  " +
//                        " from act_hi_procinst pins " +
//                        " left join act_ru_task task on pins.PROC_INST_ID_ = task.PROC_INST_ID_ " +
//                        " left join act_re_procdef procdef on pins.PROC_DEF_ID_ = procdef.ID_ " +
//                        " left join  " +
//                        " ( " +
//                        " select lk.TASK_ID_ as TASK_ID_,GROUP_CONCAT(u.user_name) as GROUP_USER from act_ru_identitylink lk left join se_user u on lk.USER_ID_ = u.user_id  " +
//                        "  where lk.TYPE_ = 'candidate' group by lk.TASK_ID_ " +
//                        " ) t on task.ID_ = t.TASK_ID_ ";
//        return sql;
//    }
//
//
//
//    /*
//     * ---- SQL查询待办方法
//     */
//	/*
//  	  select * from (
//	  SELECT DISTINCT
//		INS.BUSINESS_KEY_ as BUSSINESSKEY,
//	  TASK.ID_ as TASKID,
//	  TASK.EXECUTION_ID_ as EXECUTIONID,
//	  TASK.PROC_INST_ID_ as PROCINSID,
//	  TASK.PROC_DEF_ID_ as PROCDEFID,
//	  TASK.NAME_ as TASKNAME,
//	  TASK.TASK_DEF_KEY_ as TASKDEFKEY,
//	  TASK.CREATE_TIME_ as TASKCREATETIME,
//	  'assignee' as ASSIGNTYPE,
//	  TASK.ASSIGNEE_ as TASKUSERID
//	  FROM ACT_RU_TASK TASK
//	  LEFT JOIN ACT_RE_PROCDEF D on TASK.PROC_DEF_ID_ = D.ID_
//		LEFT JOIN ACT_HI_PROCINST INS on TASK.PROC_INST_ID_ = INS.ID_
//		WHERE TASK.ASSIGNEE_ IS NOT NULL  AND TASK.SUSPENSION_STATE_ = '1'
//
//	  UNION
//
//	  SELECT DISTINCT
//		INS.BUSINESS_KEY_ as BUSSINESSKEY,
//	  TASK.ID_ as TASKID,
//	  TASK.EXECUTION_ID_ as EXECUTIONID,
//	  TASK.PROC_INST_ID_ as PROCINSID,
//	  TASK.PROC_DEF_ID_ as PROCDEFID,
//	  TASK.NAME_ as TASKNAME,
//	  TASK.TASK_DEF_KEY_ as TASKDEFKEY,
//	  TASK.CREATE_TIME_ as TASKCREATETIME,
//	  I.TYPE_ as ASSIGNTYPE,
//	  I.USER_ID_ as TASKUSERID
//	  FROM ACT_RU_TASK TASK
//		LEFT join ACT_RE_PROCDEF D on TASK.PROC_DEF_ID_ = D.ID_
//	  left join ACT_RU_VARIABLE V ON V.PROC_INST_ID_=TASK.PROC_INST_ID_
//	  LEFT JOIN ACT_RU_IDENTITYLINK I ON I.TASK_ID_ = TASK.ID_
//		LEFT JOIN ACT_HI_PROCINST INS on TASK.PROC_INST_ID_ = INS.ID_
//	  WHERE TASK.ASSIGNEE_ IS NULL AND I.TYPE_ = 'candidate'  AND TASK.SUSPENSION_STATE_ = '1'
//	  ) ACTIVITI
//	 */
//
//
//
///*	--------- 当前步骤
//	select
//	task.ID_,
//	task.NAME_,
//	task.TASK_DEF_KEY_,
//	pins.BUSINESS_KEY_,
//	procdef.KEY_,
//	t.GROUP_USER
//	from act_hi_procinst pins
//	left join act_ru_task task on pins.PROC_INST_ID_ = task.PROC_INST_ID_
//	left join act_re_procdef procdef on pins.PROC_DEF_ID_ = procdef.ID_
//	left join
//	(
//	select lk.TASK_ID_ as TASK_ID_,GROUP_CONCAT(u.user_name) as GROUP_USER from act_ru_identitylink lk left join se_user u on lk.USER_ID_ = u.user_id
//	 where lk.TYPE_ = 'candidate' group by lk.TASK_ID_
//	) t on task.ID_ = t.TASK_ID_
//*/
//
//
//
///*
//	 ------- 历史轨迹
//	select
//	taskhis.ID_,
//	taskhis.NAME_,
//	taskhis.TASK_DEF_KEY_,
//	taskhis.START_TIME_,
//	taskhis.END_TIME_,
//	taskhis.ASSIGNEE_,
//	pins.BUSINESS_KEY_,
//	procdef.KEY_
//	from
//	act_hi_taskinst taskhis
//	left join act_hi_procinst pins on taskhis.PROC_INST_ID_ = pins.PROC_INST_ID_
//	left join act_re_procdef procdef on pins.PROC_DEF_ID_ = procdef.ID_
//	*/
//
//// ---- 查询当前流程实例及所有激活的用户待办
////	select
////	distinct
////	task.name_ as taskName,
////	task.task_def_key_ as taskDefKey,
////	task.id_ as taskId,
////	task.CREATE_TIME_ as taskCreateTime,
////	instan.business_key_ as businessKey,
////	procdef.id_ as procDefId,
////	instan.START_TIME_ as instanStartTime
////	from act_ru_task task
////	left join act_hi_procinst instan on task.proc_inst_id_ = instan.proc_inst_id_
////	left join act_re_procdef procdef on instan.proc_def_id_ = procdef.id_
////	order by instan.business_key_, instan.START_TIME_ desc , task.CREATE_TIME_ desc
//
//
//    /**
//     * 获取流程定义中的节点
//     *
//     * @param procDefId
//     * @throws Exception
//     */
//    public void getNodeOfProcessDefined(String procDefId) throws Exception {
//        BpmnModel model = repositoryService.getBpmnModel(procDefId);
//        if (model != null) {
//            Collection<FlowElement> flowElements = model.getMainProcess().getFlowElements();
//            for (FlowElement e : flowElements) {
//                System.out.println("flowelement id:" + e.getId() + "  name:" + e.getName() + "   class:" + e.getClass().toString());
//
//                if ("org.activiti.bpmn.model.UserTask".equals(e.getClass().getName())) {
//                    System.out.println(" ----------------------  Task Info [" + e.getName() + "] start ------------------ ");
//                    System.out.println(e.getId());
//                    System.out.println(e.getName());
//                    System.out.println(e.getAttributes());
//                    UserTask t = (UserTask) e;
//                    System.out.println(t.getCandidateUsers());
//                    System.out.println(" ----------------------  Task Info [" + e.getName() + "] end------------------ ");
//                }
//            }
//        }
//    }
//
//    /**
//     * tangzc1
//     * @param userId
//     * @return
//     */
//
//    public List<HistoricTaskInstance> getHistoryByAssignee(String userId) {
//        return historyService.createHistoricTaskInstanceQuery()
//                .taskAssignee(userId)
//                .finished()
//                .list();
//    }
//    /**
//     * tangzc1
//     * @param userId
//     * @return
//     */
//    public List<HistoricTaskInstance> getHistoryByCandidateUser(String userId) {
//        return historyService.createHistoricTaskInstanceQuery().taskCandidateUser(userId).finished().list();
//    }
//
//    /**
//     * 查询已处理待办
//     * @author tangzc1
//     * @param assigneeOrcandidate
//     * @return
//     */
//    public List<HistoricTaskInstance> queryHistoryTaskForUser(String assigneeOrcandidate) {
//        System.out.println("================ queryHistoryTaskForUser [" + assigneeOrcandidate
//                + "] Start ===================");
//        List<HistoricTaskInstance> taskList = new ArrayList<HistoricTaskInstance>();
//        taskList.addAll(getHistoryByAssignee(assigneeOrcandidate));
//        taskList.addAll(getHistoryByCandidateUser(assigneeOrcandidate));
//        System.out.println("================ queryHistoryTaskForUser [" + assigneeOrcandidate
//                + "] End ===================");
//        return taskList;
//    }
//
//    public ClassPathXmlApplicationContext getContext() {
//        return context;
//    }
//
//    public void setContext(ClassPathXmlApplicationContext context) {
//        this.context = context;
//    }
//
//    public ProcessEngine getProcessEngine() {
//        return processEngine;
//    }
//
//    public void setProcessEngine(ProcessEngine processEngine) {
//        this.processEngine = processEngine;
//    }
//
//    public RuntimeService getRuntimeService() {
//        return runtimeService;
//    }
//
//    public void setRuntimeService(RuntimeService runtimeService) {
//        this.runtimeService = runtimeService;
//    }
//
//    public RepositoryService getRepositoryService() {
//        return repositoryService;
//    }
//
//    public void setRepositoryService(RepositoryService repositoryService) {
//        this.repositoryService = repositoryService;
//    }
//
//    public TaskService getTaskService() {
//        return taskService;
//    }
//
//    public void setTaskService(TaskService taskService) {
//        this.taskService = taskService;
//    }
//
//    public ManagementService getManagementService() {
//        return managementService;
//    }
//
//    public void setManagementService(ManagementService managementService) {
//        this.managementService = managementService;
//    }
//
//    public IdentityService getIdentityService() {
//        return identityService;
//    }
//
//    public void setIdentityService(IdentityService identityService) {
//        this.identityService = identityService;
//    }
//
//    public HistoryService getHistoryService() {
//        return historyService;
//    }
//
//    public void setHistoryService(HistoryService historyService) {
//        this.historyService = historyService;
//    }
//
//    public FormService getFormService() {
//        return formService;
//    }
//
//    public void setFormService(FormService formService) {
//        this.formService = formService;
//    }
//
//}
